/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.asportoonline.business.beans;

import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import org.asportoonline.business.delegates.LocaleManagerDelegate;
import org.asportoonline.entities.Locale;
import org.asportoonline.entities.Prodotto;
import org.asportoonline.integration.LocaleFacade;

/**
 *
 * @author Valerio Costmagna <costamagna.valerio@gmail.com>
 */
@Stateless
public class WebServiceManager implements WebServiceManagerLocal {
@EJB
private LocaleFacade localeFacade;
//@EJB
//private LocaleManager lm;
private LocaleManager lm = new LocaleManagerDelegate();
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    
    @Override
    public List<String> cercaTutteLocalita() {
        return localeFacade.fetch_all_locality();
        
    }

    @Override
    public List<String[]> elencoLocali() {
        
       // List<Locale> ll = lm.elencoLocali();
        List<Locale> ll = localeFacade.findAll();
        Locale l;
        List<String[]> lista = new ArrayList<String[]>();
        for (int i=0; i<ll.size();i++){
            l = ll.get(i);
            String[] temp = {
                l.getEmail(),
                l.getNome(),
                l.getPiva(),
                l.getPrimaApertura(),
              //  l.getSecondaApertura(),
                l.getTelefono()
               
            };
            System.out.println("debug: "+temp.toString());
            lista.add(temp);
            
        }
        return lista;                
    }

    @Override
    public List<String[]> elencoProdotti() {
        List<String[]> lista = new ArrayList<String[]>();
        List<Locale> ll = localeFacade.findAll();
        Prodotto p;
        Locale l;
        for (int i=0; i<ll.size();i++){
                    l = ll.get(i);
                    List<Prodotto> lp = l.getProdotti();
                    p = lp.get(i);
                    Double d = p.getPrezzo();
                    String[] temp = {
                        p.getDescrizione(),
                        p.getNome(),
                        d.toString()
                        
                    };
               System.out.println("debug: "+temp.toString());
               lista.add(temp);
        }

        return lista;                

    }
}
